package com.example.hhhh.util;

import android.net.Uri;
import android.os.Build;

import com.example.hhhh.APP;

import java.io.File;


/**
 * URI 相关<br>
 * getUriForFile: 获取文件 URI<br>
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2018/04/20
 *     desc  : URI 相关
 *     git   : https://github.com/Blankj/AndroidUtilCode
 * </pre>
 */
public final class UriUtils {

    private UriUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 获取文件 URI<br>
     * Return a content URI for a given file.
     *
     * @param file The file.
     * @return a content URI for a given file
     */
    public static Uri getUriForFile(final File file) {
        if (file == null) {
            return null;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            String authority = APP.getContext().getPackageName() + ".fileprovider";
            return CustomFrameworkFileProvider.getUriForFile(APP.getContext(), authority, file);
        } else {
            return Uri.fromFile(file);
        }
    }
}